import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

/**
 * @ClassName: Test1
 * @Description: TODO
 * @Author: kevinHan
 * @Date: 2019/12/12 23:31
 * @Version: 1.0
 */
public class Test1 {
    private static String s1 = "C:/Users/kevinHan/Desktop/MySQL笔记.md";
    private static String s2 = "C:/Users/kevinHan/Desktop/aa.zip";

    public static void main(String[] args) throws IOException {

        ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(s2));
        /** 给压缩的文件重新起名字 */
        ZipEntry entry = new ZipEntry("MySQL111笔记.md");
        zipOutputStream.setComment("ziptest");
        zipOutputStream.putNextEntry(entry);
        FileInputStream fileInputStream = new FileInputStream(s1);
        int len = 0;
        while ((len = fileInputStream.read()) != -1) {
            zipOutputStream.write(len);
        }
        fileInputStream.close();
        zipOutputStream.close();
    }
}
